<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>投入产出分析报表</title>
<base href="<%=basePath%>">

<%@ include file="/WEB-INF/jsp/common/common.jsp" %>

<link rel="stylesheet" href="css/jquery.datetimepicker.css" type="text/css" />
<script src="js/jquery.validate.js" type="text/javascript" ></script>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.datetimepicker.js"></script>
<!-- <script type="text/javascript" src="js/echarts/echarts.js"></script> -->
<script type="text/javascript" src="js/echarts/echarts.min.js"></script>
<!-- <script type="text/javascript" src="js/echarts/walden.js"></script> -->
<script type="text/javascript" src="js/echarts/cic.js"></script>


<style type="text/css">

    td.bg_white {
        background: #fff;
    }
    td.charts {
        padding: 50px 30px;
    }
    td.charts .charts_title {
        line-height: 40px;
        font-size: 20px;
        text-align: center;
        color: #516b91;
        font-weight: bold;
    }
    .charts_tr {
        display: none;
    }
    /* 清除浮动 */
    .clearfix:after {
      visibility: hidden;
      display: block;
      font-size: 0;
      content: " ";
      clear: both;
      height: 0;
    }
    .hide {
        display: none;
    }
    /* -------------------------------- 查询条件 start -------------------------- */
    /* .filter_condition select,
    .filter_condition input {
        width: 150px;
        height: 30px;
        line-height: 28px;
        padding-left: 8px;
    }
    .filter_condition span {
        padding-right: 15px;
    }
    .filter_condition .tab_btn {
        width: 10px;
        height: 10px;
        margin: 0 10px;
    } */

    /* -------------------------------- 查询条件 end -------------------------- */
    .policyAmountTable .border_bottom,
    .subtable .border_bottom {
        border-bottom: 1px solid #bbcddb;
    }
    .dept_compared_box {
        position: relative;
    }
    /*------------------------------- 20190903 lfd added 修改样式 start -------------------------------------*/

    .select_div {
        position: absolute;
        right: 20px;
        top: 30px;
    }

    .select_div select{
        width: 150px;
        height: 30px;
        line-height: 28px;
        padding-left: 8px;
        -moz-border-radius: 8px;
             border-radius: 8px;
        border: 1px solid #eee;
    }

    /* .filter_condition .tab_btn {
        width: 10px;
        height: 10px;
        margin: 0 10px;
    }  */
    /* --------- common start ----------- */
    /* 清除浮动 */
    .clear {
        clear: both;
    }

    .w_50 {
        width: 50%;
        display: inline-block;
    }
    /* --------- common end ----------- */
    .search_container, .query_results, .chart_box {
        padding: 10px 20px;
        -moz-border-radius: 20px;
             border-radius: 20px;
        background: #fff;
        margin: 10px 20px 10px 10px;
        -moz-box-shadow: 0px 0px 15px #eee; /* 老的 Firefox */
        -webkit-box-shadow: 0px 0px 15px #eee;
                box-shadow: 0px 0px 15px #eee;
        line-height: 30px;
        -webkit-box-sizing: border-box;
           -moz-box-sizing: border-box;
                box-sizing: border-box;
    }
    .search_container .search_tit, .query_results .query_tit{
        color: #f38963;
        font-size: 16px;
        font-weight: 700;
        padding-bottom: 20px;
    }
    .search_container .search_item {
        width: 30%;
        margin: 5px 1.5%;
        float: left;
    }
    .search_container .search_item span {
        width: 90px;
        display: inline-block;
    }

    .search_container .search_item .hide {
        display: none;
    }
    .search_container .search_item input,
    .search_container .search_item select {
        width: 120px;
        height: 30px;
        line-height: 30px;
        -moz-border-radius: 3px;
             border-radius: 3px;
    }

    .search_container .search_item .readonly{
        background: #eee;
    }

    .search_container .search_item .input_button_s {
        width: 55px;
        line-height: 30px;
        text-align: center;
        -moz-border-radius: 4px;
             border-radius: 4px;
        border-style: none;
        /* border: none; */
        background: #3cabd3;
        color: #fff;
    }
    /* ------ 单选框、多选框样式 start ----- */
    .search_container .search_item label.check_span {
        position: relative;
        display: inline-block;
    }
    .search_container .search_item input[type="checkbox"],
    .search_container .search_item input[type="radio"]{
        width: 15px;
        height: 15px;
        opacity: 0;
        margin-left: 10px;
    }
    .search_container .search_item .check_span label {
        position: absolute;
        left: 0px;
        top: 6px;
        width: 15px;
        height: 15px;
        border: 1px solid #dcdcdc;
    }
    label.checkbox {
        -moz-border-radius: 2px;
             border-radius: 2px;
    }
    label.radio {
        -moz-border-radius: 50%;
             border-radius: 50%;
    }
    /*设置选中的input的样式*/
    /* + 是兄弟选择器,获取选中后的label元素*/
    .search_container .search_item input:checked+label {
        background-color: #3cabd3;
        border: 1px solid #3cabd3;
    }
    .search_container .search_item input:checked[type="checkbox"]+label::after {
        position: absolute;
        content: "";
        width: 5px;
        height: 7px;
        top: 2px;
        left: 4px;
        border: 2px solid #fff;
        border-top: none;
        border-left: none;
        -webkit-transform: rotate(45deg);
           -moz-transform: rotate(45deg);
                transform: rotate(45deg)
    }
    .search_container .search_item input:checked[type="radio"]+label::after {
        position: absolute;
        content: "";
        width: 5px;
        height: 5px;
        -moz-border-radius: 3px;
             border-radius: 3px;
        background: #fff;
        top: 5px;
        left: 5px;
    }
    /* ------ 单选框、多选框样式 end ----- */
    .search_container .search_btns {
        padding: 20px;
        text-align: center;
    }
    .search_container .search_btn,
    .search_div .table_div .search_btn {
        border: 1px solid #3cabd3;
        background: #fff;
        -moz-border-radius: 15px;
             border-radius: 15px;
        height: 30px;
        line-height: 30px;
        padding: 0 15px;
        color: #3cabd3;
        outline: none;
    }
    .search_container .search_btn.reset,
    .search_div .table_div .search_btn.reset {
        border: 1px solid #b5b5b5;
        color: #7f7f7f;
    }
    /* 提示信息样式 */
    /* .query_results.tip_box {
        display: none;
    }
    .query_results .close_tips {
        float: right;
        padding-right: 15px;
        font-size: 15px;
        color: #3cabd3;
        cursor: pointer;
    } */
    .query_results .tips {
        color: #3cabd3;
        float: right;
        font-size: 12px;
        font-weight: 400;
    }
    /* 表格样式修改 start */
    .query_results .content_table_1 {
        border-collapse: collapse;
    }

    .query_results .content_table_1 .f1 {
        background: #d8eef6;
        height: 30px;
        line-height: 30px;
    }
    .query_results .content_table_1 th,
    .query_results .content_table_1 td {
        border: 1px solid #d2d2d2;
    }
    .query_results .content_table_1 .f1 th {
        background: #d8eef6;
    }
    .next_tr {
        background: #eee;
    }
    .page {
        background: transparent;
        margin-top: 15px;
    }
    .policyAmountTable .see_span {
        color: #f5996c;
        border: 1px solid #f5996c;
        -moz-border-radius: 3px;
             border-radius: 3px;
        line-height: 22px;
        width: 50px;
        display: inline-block;
        margin: 3px 5px;
    }
    /* 表格样式修改 end */
    /* 弹窗样式 start */
    .search_div {
        -moz-border-radius: 20px;
             border-radius: 20px;
    }
    .search_div .table_div {
        padding: 30px 20px 10px;
    }
    .search_div .table_div .table_tit {
        font-weight: 700;
        font-size: 20px;
        text-align: center;
        line-height: 48px;
        height: 48px;
    }
    .search_div .table_div .search_row {
        height: 40px;
        line-height: 40px;
    }
    .search_div .table_div .search_item  {
        float: left;
    }
    .search_div .table_div .queryResults {
        padding-top: 10px;
        height: 216px;
        overflow-y: auto;
        overflow-x: hidden;
    }
    .search_div  .popup_button {
        margin: 10px 3px 20px;
        background: -webkit-gradient(linear, left top, right top, from(#319dcf), to(#085192));
        background: -webkit-linear-gradient(left, #319dcf, #085192);
        background: -moz-linear-gradient(left, #319dcf, #085192);
        background: linear-gradient(to right, #319dcf, #085192); /* 标准的语法 */
        width: 80px;
        height: 30px;
        line-height: 30px;
        -moz-border-radius: 5px;
             border-radius: 5px;
        color: #fff;
        border-style: none;
        border: 1px solid #319dcf;
    }
    .search_div  .popup_button.cancel {
        color: #a0a0a0;
        background: #fff;
        border: 1px solid #a0a0a0;
    }
    /* 弹窗样式 end */
    /*------------------------------- 20190903 lfd added 修改样式 end -------------------------------------*/
    /* lfd changed 20191118 下级表格样式  */
    .subtable_box {
        padding: 20px 10px;
        background: #fffaf8;
    }
    .query_results .subtable_box .content_table_1 .f1{
        background: #fbe7dd;
    }
    .query_results .subtable_box .content_table_1 .f1 th {
        background: transparent;
    }
    /* ---------- 图表样式添加 start ------------ */
    .charts_container {
        padding: 0;
        margin: 10px 20px 10px 10px
    }

    .chart_container {
        float: left;
        -webkit-box-sizing: border-box;
           -moz-box-sizing: border-box;
                box-sizing: border-box;
        margin: 0;
        padding: 20px 0;
        width: 100%;
        position: relative;
    }
    .chart_container.w_50 {
        width: 50%;
    }
    .chart_container.l20 {
        padding-left: 20px;
    }
    .chart_container.r20 {
        padding-right: 20px;
    }
    .chart_container .chart_box {
        -webkit-box-sizing: border-box;
           -moz-box-sizing: border-box;
                box-sizing: border-box;
        margin: 0;
        padding: 20px;
    }
    /* ---------- 图表样式添加 end ------------ */
     .query_results .content_table_1 .noborder {
        border: none;
    }
</style>
<body>
    <div class="current">
        <table class="current_table_1">
            <tbody>
                <tr class="f2">
                    <td><img src="./images/current_1.jpg"></td>
                    <td class="current_table_1_td"><img src="images/current_1.png">
                        当前位置：统计分析<span style="padding: 0 4px; font-weight: bold; line-height: 28px;">&gt;</span>投入产出分析报表<span style="padding: 0 4px; font-weight: bold; line-height: 28px;">&gt;</span>详情
                    </td>
                    <td><img src="./images/current_3.jpg"></td>
                </tr>
            </tbody>
        </table>
    </div>

    <div class="search_container">
        <div class="search_tit">查询条件</div>
        <div class="search_box">
            <div class="search_item">
                <span>合作伙伴名称：</span>
                <!-- <select name="ptn_name" id="ptn_name"></select> -->
                <input name="ptn_name" id="ptn_name" readonly="readonly" class="input_text readonly"/><span class="hide" id="ptn_code"></span>
                <input type="button" class="input_button_s" value="请选择" onClick="setPartnerParam(1)" />
            </div>
            <div class="search_item">
                <span>产品线：</span>
                <!-- 1 人险 2 财险 3 新意健险 4 车险 5 信用保证险  99 责任险 -->
                <select name="product_line" id="product_line">
                    <option value="">--请选择--</option>
                    <option value="1">人险</option>
                    <option value="2">财险</option>
                    <option value="4">车险</option>
                    <option value="5">信保</option>
                    <option value="3">意健险</option>
                    <option value="99">责任险</option>
                </select>
            </div>
            <div class="search_item">
                <span>日期：</span>
                <input name="currentTime" id="currentTime" readonly="readonly" class="input_text"/>
            </div>
            <div class="clear"></div>
        </div>
        <div class="search_box">
            <div class="search_item">
                <span>查询内容：</span>
                <label class="check_span">
                    <input type="checkbox" class="tab_btn" id="ispolicy" checked="checked"/><label for="ispolicy" class="checkbox"></label>单量
                </label>
                <label class="check_span">
                    <input type="checkbox" class="tab_btn" id="ispremium" checked="checked"/><label for="ispremium" class="checkbox"></label>保费
                </label>
            </div>
            <div class="search_item">
                <span>数字格式：</span>
                <label  class="check_span">
                    <input type="radio" class="tab_btn" name="number_format" checked id="numberFormat0" value="0"/><label for="numberFormat0" class="radio"></label>个
                </label>
                <label class="check_span">
                    <input type="radio" class="tab_btn" name="number_format" id="numberFormat1" value="1"/><label for="numberFormat1" class="radio"></label>万
                </label>
            </div>
            <div class="clear"></div>
        </div>
        <div class="search_btns">
            <input type="button" class="search_btn reset" value="重置" onClick="reset()" />
            <input type="button" class="search_btn" value="查询" onClick="setAmountParam()" />
        </div>
    </div>

    <div class="search_container">
        <div class="search_box">
            <div class="search_item">
                <span>投入成本：</span>
                <span id="channelCost"></span>
            </div>
            <div class="search_item">
                <span>总量：</span>
                <span id="summary"></span>
            </div>
            <div class="search_item">
                <span>投产比：</span>
                <span id="productionRatio"></span>
            </div>
            <div class="clear"></div>
        </div>
    </div>

    <!-- 提示信息 -->
    <!-- <div class="query_results tip_box" id="tip_box">
        <div class="query_tit">提示信息<span class="close_tips" onclick="closeCurrentDIV('tip_box')">关闭</span></div>
    </div> -->

     <!-- 单量、保费表格 start -->
    <div class="query_results" style="padding-bottom: 30px;">
        <div class="query_tit">查询结果        <span class="tips"></span></div>

        <div  onclick="toggle_subbox()">
            <table id="policyAmountTable" class="content_table_1 policyAmountTable">
                <thead>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
        <div class="subtable_box">
            <table id="subtable" class="content_table_1 subtable">
                <thead>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
    <!-- 单量、保费表格 end  -->
    <!-- 图表 start -->
    <div class="charts_container">
        <!-- 保费趋势图 start -->
        <div class="chart_container partner_month_tr">
            <div id="partner_month_title" class="charts_title"></div>
            <div id="partner_month" class="chart_box" style="width: 100%;height:400px;"></div>
        </div>
        <!-- 保费趋势图 end -->
        <!-- 单量、保费汇总 start -->
        <div class="chart_container dept_amount_tr">
            <div id="dept_amount_title" class="charts_title"></div>
            <div id="dept_amount" class="chart_box" style="width: 100%;height:400px;"></div>
        </div>
        <!-- 单量、保费汇总 end -->
        <!-- 各机构趋势图 start -->
        <div class="chart_container dept_compared_tr">
            <div id="dept_compared_title" class="charts_title"></div>
            <div id="dept_compared" class="chart_box" style="width: 100%;height:400px;"></div>
            <div class="select_div">
                <span class="type_select_div">
                    <select name="type_select" id="type_select"></select>
                </span>
            </div>
        </div>
        <!-- 各机构趋势图 end -->
        <!-- 各机构按时间对比图 start -->
        <div class="chart_container dept_quantity_tr">
            <div id="dept_quantity_title" class="charts_title"></div>
            <div id="dept_quantity" class="chart_box" style="width: 100%;height:700px;"></div>
        </div>
        <!-- 各机构按时间对比图 end -->
    </div>
    <!-- 图表 end -->
    <!-- 查询合作伙伴 弹窗 start -->
    <div id="searchPartnerDiv"  class="search_div" style="display:none;width:60%;">
        <div  class="table_div">
            <div class="table_tit">查询合作伙伴名称</div>
            <div class="table_box">
                <div class="search_div">
                    <div class="search_row">
                        <span class="search_item w_50">合作伙伴名称：
                            <input id="partner_name" type="text" class="input_text">
                        </span>
                        <span class="search_item w_50">合作伙伴代码：
                            <input id="partner_code" type="text" class="input_text">
                        </span>
                        <div class="clear"></div>
                    </div>
                    <div class="search_row">
                        <input type="button" class="search_btn" value="查询" onclick="setPartnerParam(1)">
                        <input type="button" class="search_btn reset" value="重置" onclick="tempReset()">
                    </div>
                </div>
            </div>
            <div class="queryResults">
                <table id="templetTable" class="content_table_1">
                    <thead>
                        <tr class="f1">
                            <th style="width: 5%">选择</th>
                            <th style="width: 60%">合作伙伴名称</th>
                            <th style="width: 25%">合作伙伴代码</th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
                <div id="templetpageDIV" class="page"></div>
            </div>
        </div>
        <div align="center" >
            <input class="popup_button" type="button" value="确定" onclick="setPartner(0)">
            <input class="popup_button cancel" type="button" value="取消" onclick="closePartnerDiv()">
        </div>
    </div>
    <!-- 查询合作伙伴 弹窗 end -->

    <script>
    // 全局 单位
    var unit = ''

    /**
     * 将长数字格式化
     * @DateTime  2018-01-18
     * @version   1.0
     * @param     {num}       num       将要格式化的数字
     * @param     {num}       precision 小数保留位数
     * @param     {string}    separator 分隔符
     * @return    {string}              格式化后的数字 例如 "1,000" 或者 "56 000.00"
     */
    function formatNumber(num, precision, separator, level) {
      var parts
      // 判断是否为数字
      if (!isNaN(parseFloat(num)) && isFinite(num)) {
        // 把类似 .5, 5. 之类的数据转化成0.5, 5, 为数据精度处理做准备
        // 为什么不在判断中直接写 if (!isNaN(num = parseFloat(num)) && isFinite(num))
        // parseFloat有一个奇怪的精度问题, 比如 parseFloat(12312312.1234567119) 的值变成了 12312312.123456713
        num = Number(num)

        // 处理量级
        if(level) {
            num = num/level
         }

        // 处理小数点位数
        num = (typeof precision !== 'undefined' ? num.toFixed(precision) : num).toString()
        // 分离数字的小数部分和整数部分
        parts = num.split('.')
        // 整数部分加[separator]分隔, 借用一个著名的正则表达式
        // parts[0] = parts[0].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + (separator || ','))
        parts[0] = parts[0].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + (separator || ''))
        return parts.join('.')
      }
      return NaN;
    }

    /**
     * 对Date的扩展，将 Date 转化为指定格式的String
     * 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
     * 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
     * @param     {string}       num       格式
     * @example   (new Date()).Format('yyyy-MM-dd hh:mm:ss.S') ==> 2006-07-02 08:09:04.423
     *            (new Date()).Format('yyyy-M-d h:m:s.S')      ==> 2006-7-2 8:9:4.18
     */
    Date.prototype.Format = function (fmt) {
      var o = {
        'M+': this.getMonth() + 1, //月份
        'd+': this.getDate(), //日
        'h+': this.getHours(), //小时
        'm+': this.getMinutes(), //分
        's+': this.getSeconds(), //秒
        'q+': Math.floor((this.getMonth() + 3) / 3), //季度
        'S': this.getMilliseconds() //毫秒
      }
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
      }
      for (var k in o) {
        if (new RegExp('(' + k + ')').test(fmt)) {
          fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
        }
      }
      return fmt
    }
    // 取近12个月日期
    function last_year_month() {
        var currentTime = $('#currentTime').val()
        var d = currentTime?new Date(currentTime.replace(/-/g, '/')) :new Date();
        var result = [];
        for(var i = 0; i < 12; i++) {
            var m = d.getMonth() + 1;
            m = m < 10 ? "0" + m : m;
            //在这里可以自定义输出的日期格式
            result.unshift(d.getFullYear() + "-" + m );
            d.setMonth(d.getMonth() - 1);
        }
        return result;
    }
    /* 设置表格头 */
    function getHead () {
        var month_str = ''
        $.each(last_year_month(), function(index, el) {
            month_str += '<th style="width:6%;">' + el + '</th>'
        });

        return  month_str
    }

    //获取url中的参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return r[2]; return null; //返回参数值
    }

    /* 重置按钮 */
    function reset() {
        $('#product_line').val('')
        $('#currentTime').val('')
        $('.tab_btn').attr("checked","checked")
        $('#numberFormat0').attr("checked", true)
        $('#ptn_name').val('')

        var partnerCode = getUrlParam('partnerCode')
        if (partnerCode) {
            $('#ptn_code').val(partnerCode)
            // 查询图表数据
            setAmountParam(partnerCode)
        }
    }
    /* 选择判断今天不能选 */
    function changeTermDate(){
        var countDate = new Date($("#currentTime").val().replace(/-/g, '/'));
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()
        var day = date.getDate()
        var nowDate = new Date(year, month, day)
        if(countDate >= nowDate){
            $("#currentTime").val('')
            alert('请选择今天之前的日期。')
        }
    }
    /* 初始化 */
    $(function () {
        /* 选择日期 */
        $('#currentTime').datetimepicker({
            lang: 'ch',
            validateOnBlur: false,
            timepicker: false,
            format: 'Y-m-d',
            maxDate: '0',
            onChangeDateTime: changeTermDate, // 回调函数
            scrollMonth: false,
            scrollTime: false
        });

        /* 获取合作伙伴名称 */
        // queryPtnName()

        // 合作伙伴代码 合作伙伴名称显示 查询数据
        // var partnerName = getUrlParam('partnerName')
        var partnerCode = getUrlParam('partnerCode')

        /* if (partnerName) {
            $('#ptn_name').val(partnerName)
        } */

        if (partnerCode) {
            $('#ptn_code').val(partnerCode)

            // 查询图表数据
            setAmountParam(partnerCode)
            // 查询成本费用
            // getChannelCost(getUrlParam('partnerCode'))
        }
    })

    /* 查询合作伙伴 */
    /* function queryPtnName() {
        $.ajax({
            url : "dataManage/queryPtnName",
            type : 'POST',
            async : true,
            dataType:'json',
            success : function(data) {
                var str = '<option value="">--请选择--</option>'
                $.each(data, function (i, v) {
                    str += '<option value="' + v.PARTNER_CODE + '">' + v.PARTNER_CODE + '--' + v.CHANNEL_NAME +  '</option>'
                })
                $('#ptn_name').html(str)
                $('#ptn_name').val(getUrlParam('partnerCode'))
            }
        })
    } */
    /* --------------------表格 start---------------------------- */
    /* 配置参数 */
    function setAmountParam(partnerCode) {
        var jsonData = {
            "countDate": $('#currentTime').val()?$('#currentTime').val():(new Date()).Format('yyyy-MM-dd'),
            "partnerCode": partnerCode?partnerCode:$('#ptn_code').val(),
            "ispolicy": document.getElementById('ispolicy').checked,
            "ispremium": document.getElementById('ispremium').checked,
            "policyType": $('#product_line').val()=="99"?"2":($('#product_line').val()||''),
            "isLiability": $('#product_line').val()=="99"?true:false
        }

        // 清除数据
        $('#summary').html('')
        $('#channelCost').html('')
        $('#productionRatio').html('')

        // 清楚表格
        var tableObj = $("#policyAmountTable");
        tableObj.find("tbody").empty();

        // 清除echarts实例 -----------------------
        // 保费趋势图清除
        echarts.init(document.getElementById('partner_month')).dispose();
        $('.partner_month_tr').hide()
        // 合作伙伴各机构保费对比图
        echarts.init(document.getElementById('dept_amount')).dispose();
        $('.dept_amount_tr').hide()
        // 各机构趋势图
        echarts.init(document.getElementById('dept_compared')).dispose();
        $('.dept_compared_tr').hide()
        // 各机构对比图
        echarts.init(document.getElementById('dept_quantity')).dispose();
        $('.dept_quantity_tr').hide()
        // 清除echarts实例 -----------------------
        
        // 清除机构下数据
        close_subbox()

        queryDeptAmount(jsonData)

        // 清除数据
        /* $('#summary').html('')
        $('#channelCost').html('')
        $('#productionRatio').html('') */


        // 查询成本费用
        // getChannelCost(jsonData.partnerCode)


        // 投产比
        /* var i = 0
        var proInterval = setInterval(function () {
            i++
            var summary = $('#summary').html() - 0

            var channelCost = $('#channelCost').html() - 0

            if (summary && channelCost) {
                $('#productionRatio').html('1/' + (summary/channelCost).toFixed(2))
                clearInterval(proInterval)
            }
        },100)


        setTimeout(function () {
            clearInterval(proInterval)
        }, 2000) */
    }
    /* 获取数据 */
    function queryDeptAmount (jsonData) {
        if(!jsonData || (!jsonData.ispolicy && !jsonData.ispremium)){
            $.message("error", "请选择至少一项进行查询！");
            return false
        }
        $.openLoading();
        $.ajax({
            url : "dataManage/querypartnerAmount",
            type : 'POST',
            async : true,
            dataType:'json',
            data: jsonData,
            success : function(data) {
                $.closeLoading();

                // 查询单位变化 全局 lfd added 20191114
                if ($('#numberFormat1').attr('checked')) {
                    unit = '万'
                } else {
                    unit = ''
                }

                // 进入时 合作伙伴名称显示
                if (!$('#ptn_name').val()) {
                    $('#ptn_name').val(data[0].CHANNEL_NAME)
                }

                var policy_thead_str = '<tr class="f1"><th style="width:4%;">序号</th><th style="width:6%;">合作伙伴</th>'
                + getHead()
                + '<th style="width:5%;">近12个月</th>'
                + '<th style="width:5%;">本年</th>'
                + '<th style="width:5%;">总量</th></tr>'
                $('#policyAmountTable').find('thead').html(policy_thead_str)

                // 整理数据
                if (unit === '万') {
                    $.map(data, function (v, i) {
                        for(prop in v) {
                            if (prop != 'DEPT_ABR' && prop != 'DEPT_CODE' && prop != 'PARTNER_CODE'&& prop != 'CHANNEL_NAME' && prop != 'CHANNEL_COST') {
                                v[prop] = formatNumber(v[prop], 2, '', 10000)
                            }
                        }
                        return v
                    })
                }

                // 总量数据
                if (data.length>0) {
                    // 单位总为万
                    var summary = 0
                    if ($('#numberFormat1').attr('checked')) {
                        summary = data[0].PREMIUM
                    } else {
                        summary = formatNumber((data[0].PREMIUM), 2, '', 10000)
                    }
                    $('#summary').html(summary + '万元')
                } else {
                    $('#summary').html(0)
                }
                // 投产比
                var channelCost = data[0].CHANNEL_COST
                if (channelCost) {
                    $('#channelCost').html(channelCost + '万元')
                    $('#productionRatio').html('1/' + (summary/channelCost).toFixed(2))
                } else {
                    $('#channelCost').html('--')
                    $('#productionRatio').html('--')
                }

                var str = ''
                $.each(data, function (i, v){
                    str += '<tr class="f2"><td>' + data.length + '</td><td>' + v.PARTNER_CODE +'-' + v.CHANNEL_NAME + '</td><td>'
                    if (jsonData.ispolicy && jsonData.ispremium){
                        for (k = 11; k>=0; k--) {
                            str += '<div class="border_bottom">' + v['COUNT' + k] + '</div><div>' + v['PREMIUM' + k] + '</div></td><td>'
                        }
                        str += '<div class="border_bottom">' + v['COUNT12'] + '</div><div>' + v['PREMIUM12'] + '</div></td>'
                            // 20191008 lfd added
                            + '<td><div class="border_bottom">' + v.ANNUAL_TOTAL_POL + '</div><div>' + v.ANNUAL_TOTAL_PREMIUM + '</div></td>'
                            + '<td><div class="border_bottom">' + v.POL_NUM + '</div><div>' + v.PREMIUM + '</div></td>'
                            + '</tr>'
                    } else if (jsonData.ispolicy) {
                        for (k = 11; k>=0; k--) {
                            str += v['COUNT' + k] + '</div></td><td>'
                        }
                        str += v['COUNT12'] + '</div></td>'
                        // 20191008 lfd added
                        + '<td>' + v.ANNUAL_TOTAL_POL + '</td>'
                        + '<td>' + v.POL_NUM + '</td>'
                        + '</tr>'
                    } else if (jsonData.ispremium){
                        for (k = 11; k>=0; k--) {
                            str += v['PREMIUM' + k] + '</div></td><td>'
                        }
                        str += v['PREMIUM12'] + '</div></td>'
                        // 20191008 lfd added
                        + '<td>' + v.ANNUAL_TOTAL_PREMIUM + '</td>'
                        + '<td>' +  v.PREMIUM + '</td>'
                        + '</tr>'
                    } else {
                        str = ''
                    }
                })

                var tableObj = $("#policyAmountTable");
                tableObj.find("tbody").empty();
                tableObj.find("tbody").append(str);

                // todo 查询下级数据
                queryPartner(jsonData)
                // 显示 lfd added 20191121
                $('.subtable_box').show()


                // 保费趋势图清除
                /* echarts.init(document.getElementById('partner_month')).dispose();
                $('.partner_month_tr').hide() */

                // 合作伙伴名称
                if (data.length >0) {
                    jsonData.CHANNEL_NAME = data[0].CHANNEL_NAME
                }

                // 保费趋势图查询

                if (data.length > 0) {
                    setPartnerMonthCharts(data, jsonData)
                }

                // lfd added 20191023 -------start

                // 配置提示信息内容
                var str
                if (jsonData.ispolicy && jsonData.ispremium){
                    str = "（下方表格中，每个合作伙伴对应两行，第一行为单量，单位为" + unit + "单；第二行为保费，单位为" + unit + "元。）";
                } else if (jsonData.ispolicy) {
                    str = "（下方表格中，每个合作伙伴对应数字为单量，单位为" + unit + "单。）";
                } else if (jsonData.ispremium) {
                    str = "（下方表格中，每个合作伙伴对应数字为保费，单位为" + unit + "元。）";
                }

                // 打开提示信息
                $(".tips").html(str);
                // $("#tip_box").css("display", "block");
                // 打开提示信息 lfd added 20191023 -------end

            }
        })
    }

    /* 查询机构下的数据 */
    function queryPartner(jsonData) {
        if (!jsonData || (!jsonData.ispolicy && !jsonData.ispremium))  {
            $.message("error", "请选择至少一项进行查询！");
            return false
        }

        $.openLoading();
        // 清除表格 lfd added 20190926
        $('#subtable').find('tbody').empty();
        
        // 清除图表 20191121 lfd added
        // 清除echarts实例 -----------------------
        // 合作伙伴各机构保费对比图
        echarts.init(document.getElementById('dept_amount')).dispose();
        $('.dept_amount_tr').hide()
        // 各机构趋势图
        echarts.init(document.getElementById('dept_compared')).dispose();
        $('.dept_compared_tr').hide()
        // 各机构对比图
        echarts.init(document.getElementById('dept_quantity')).dispose();
        $('.dept_quantity_tr').hide()
        // 清除echarts实例 -----------------------
        

        $.ajax({
            url : "dataManage/queryDeptPartner",
            type : 'POST',
            async : true,
            dataType:'json',
            data: jsonData,
            success : function(data) {
                $.closeLoading();

                // 清除echarts实例
                // 合作伙伴各机构保费对比图
                // echarts.init(document.getElementById('dept_amount')).dispose();
                // $('.dept_amount_tr').hide()
                // 各机构趋势图
                // echarts.init(document.getElementById('dept_compared')).dispose();
                // $('.dept_compared_tr').hide()
                // 各机构对比图
                // echarts.init(document.getElementById('dept_quantity')).dispose();
                // $('.dept_quantity_tr').hide()

                // 整理数据
                if (unit === '万') {
                    $.map(data, function (v, i) {
                        for(prop in v) {
                            if (prop != 'DEPT_ABR' && prop != 'DEPT_CODE' && prop != 'PARTNER_CODE'&& prop != 'CHANNEL_NAME') {
                                v[prop] = formatNumber(v[prop], 2, '', 10000)
                            }
                        }
                        return v
                    })
                }

                var str = ''

                $.each(data, function (i, v){
                    // 机构名称 传给图表
                    jsonData.DEPT_ABR = v.DEPT_ABR

                    str += '<tr class="' + jsonData.partnerCode + '_tr"><td class="noborder"></td><td>' + i + '</td><td>' + v.DEPT_CODE + '-' + v.DEPT_ABR + '<td>'
                    if (jsonData.ispolicy & jsonData.ispremium){
                        for (k = 11; k>=0; k--) {
                            str += '<div class="border_bottom">' + v['COUNT' + k] + '</div><div>' + v['PREMIUM' + k] + '</div></td><td>'
                        }
                        str += '<div class="border_bottom">' + v['COUNT12'] + '</div><div>' + v['PREMIUM12'] + '</div></td><td>'

                        // 20191008 lfd added
                        str += '<div class="border_bottom">' + v.ANNUAL_TOTAL_POL + '</div><div>' + v.ANNUAL_TOTAL_PREMIUM + '</div></td><td>'

                        str += '<div class="border_bottom">' + v.POL_NUM + '</div><div>' + v.PREMIUM + '</div></td></tr>'
                    } else if (jsonData.ispolicy) {
                        for (k = 11; k>=0; k--) {
                            str += v['COUNT' + k] + '</div></td><td>'
                        }
                        str += v['COUNT12'] + '</div></td><td>'

                        // 20191008 lfd added
                        str += v.ANNUAL_TOTAL_POL + '</td><td>'

                        str += v.POL_NUM + '</td></tr>'
                    } else if (jsonData.ispremium){
                        for (k = 11; k>=0; k--) {
                            str += v['PREMIUM' + k] + '</div></td><td>'
                        }
                        str += v['PREMIUM12'] + '</div></td><td>'

                        // 20191008 lfd added
                        str += v.ANNUAL_TOTAL_PREMIUM + '</td><td>'

                        str += v.PREMIUM + '</td></tr>'
                    } else {
                        str = ''
                    }
                })

                // 序号 合作伙伴名称
                // var pre_div = $('.policyAmountTable .f2')
                // pre_div.after(str)

                // lfd added 20190923

                // 进入时 合作伙伴名称显示 todo
                var policy_thead_str = '<tr class="f1"><th style="width:2%; cursor: pointer;" onclick="close_subbox()"><img src="./images/retract.png" style="width:50%;" /></th><th style="width:3%;">序号</th><th style="width:6%;">机构</th>'
                + getHead()
                + '<th style="width:5%;">近12个月</th><th style="width:5%;">本年</th><th style="width:5%;">总量</th></tr>'
                $('#subtable').find('tbody').html(policy_thead_str + str)

                // var tbody = $('.subtable tbody')
                // tbody.html(str)

                // var laststr = pre_div.html()
                // $('.' + jsonData.partnerCode + '_tr').css('background', '#fff')
                // 整理图表 如果多机构
                if (data.length > 1) {
                    // 合作伙伴各机构保费对比图   调取
                    set_dept_charts(data, jsonData)
                    // 各机构保费趋势图  调取
                    // setDeptComparedCharts(data, jsonData)
                    setDeptQuantityCharts(data, jsonData)

                    // 选择单量或者保费
                    var type_select = ''
                    if (jsonData.ispremium) {
                        type_select += '<option value="' + 0 + '">保费</option>'
                    }
                    if (jsonData.ispolicy) {
                        type_select += '<option value="' + 1 + '">单量</option>'
                    }

                    $('#type_select').html(type_select)
                    $('#type_select').val('0')

                    setDeptComparedCharts(data, jsonData)

                    $('#type_select').on('change', function () {
                        // 各机构趋势图
                        echarts.init(document.getElementById('dept_compared')).dispose();

                        setDeptComparedCharts(data, jsonData)
                    })

                }

            }
        })
    }
    /* --------------------表格 end---------------------------- */
    /* --------------------各机构保费对比图 start---------------------------- */
    /* 合作伙伴各机构保费对比图 */
    function set_dept_charts(data, jsonData) {
        $('.dept_amount_tr').show()

        // 整理图表数据
        var Axis = []
        var polnum = []
        var premium = []
        $.each(data, function (i, v){
            Axis.push(v.DEPT_ABR)
            if (jsonData.ispolicy) {
                polnum.push(v.POL_NUM)
            }
            if (jsonData.ispremium) {
                premium.push(v.PREMIUM)
            }
        })

        // set表格数据

        // $('#deptTable tbody').html(str)

        // 设置标题
        // $('#dept_amount_title').html(jsonData.CHANNEL_NAME + '各机构保费对比图')
        // var title = jsonData.CHANNEL_NAME + '合作伙伴各机构保费对比图'

        var series = []
        var legend = []
        var yAxis = []

        if (jsonData.ispolicy) {
            var json1 =  {
                name:'单量',
                type:'bar',
                barWidth: '18%',
                itemStyle: {
                    barBorderRadius: [10, 10, 0, 0],
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: '#f48e66'
                    }, {
                        offset: 0.6,
                        color: '#f48e66'
                    }, {
                        offset: 1,
                        color: '#f7b17a'
                    }])
                },
                data: polnum,
                markPoint : {
                    data : [
                        {type : 'max', name: '最大值'},
                        {type : 'min', name: '最小值'}
                    ]
                },
                markLine : {
                    data : [
                        {type : 'average', name: '平均值'}
                    ]
                }
            }
            series.push(json1)
            legend.push('单量')
        }
        if (jsonData.ispremium) {
            var json2 = {
                name:'保费',
                type:'bar',
                data: premium,
                barWidth: '18%',
                itemStyle: {
                    barBorderRadius: [10, 10, 0, 0],
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: '#45aacd'
                    }, {
                        offset: 0.6,
                        color: '#45aacd'
                    }, {
                        offset: 1,
                        color: '#7dd1ed'
                    }])
                },
                markPoint : {
                    data : [
                        {type : 'max', name: '最大值'},
                        {type : 'min', name: '最小值'}
                    ]
                },
                markLine : {
                    data : [
                        {type : 'average', name : '平均值'}
                    ]
                }
            }
            series.push(json2)
            legend.push('保费')
        }

        if (jsonData.ispolicy && jsonData.ispremium) {
            yAxis.push({
                type: 'value',
                name: '单量（' + unit + '单）',
                position: 'left'
            })
            yAxis.push({
                type: 'value',
                name: '保费（' + unit + '元）',
                position: 'right'
            })
            series[1].yAxisIndex = 1
        } else {
            yAxis.push({
                type : 'value'
            })
        }


        // 基于准备好的dom，初始化echarts实例
        //var deptChart = echarts.init(document.getElementById('dept_amount'),'westeros');
        var deptChart = echarts.init(document.getElementById('dept_amount'),'cic');

        var option = {
            title : {
                text: jsonData.CHANNEL_NAME + '各机构保费对比图',
                // top: 30,
                left: 'center'
            },
            grid: {
                top: 100
                // bottom: 80
            },
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            legend: {
                data: legend,
                top: 30,
                left: 30
            },
            toolbox: {
                show : true,
                top: 30,
                feature : {
                    dataView : {show: true, readOnly: false},
                    // magicType : {show: true, type: ['stack', 'tiled', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    data : Axis,
                    axisLabel: {
                        rotate: 45
                    }
                }
            ],
            yAxis: yAxis,
            dataZoom: [
                 {
                     type: 'inside'
                 }
             ],
            series : series
        };

        // 使用刚指定的配置项和数据显示图表。
        deptChart.setOption(option);
    }
    /* --------------------各机构保费对比图 end---------------------------- */
    /* --------------------保费趋势图 start------------------------------- */
    function setPartnerMonthCharts(data, jsonData) {
        // 初始化
        var yAxis = []
        var legend = []
        var series = []
        var polnumData = []
        var premiumData = []
        var months = last_year_month()

        // 整理数据
        var obj = data[0]
        for (var i=11; i>=0; i--) {
            if (jsonData.ispolicy) {
                polnumData.push(obj['COUNT' + i])
            }
            if (jsonData.ispremium) {
                premiumData.push(obj['PREMIUM' + i])
            }
        }

        if (jsonData.ispolicy) {
            series.push({
                name:'单量',
                type:'line',
                // lfd added 20191008
                areaStyle: {
                    normal: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: '#45aacd'
                        }, {
                            offset: 0.8,
                            color: '#f9fcfe'
                        }, {
                            offset: 1,
                            color: '#f9fcfe'
                        }])
                    }
                },
                smooth: true,
                data: polnumData
            })
            legend.push('单量')
        }

        if (jsonData.ispremium) {
            series.push({
                name:'保费',
                type:'bar',
                data: premiumData,
                barWidth: '30%',
                itemStyle: {
                    barBorderRadius: [5, 5, 0, 0],
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: '#f48e66'
                    }, {
                        offset: 0.6,
                        color: '#f48e66'
                    }, {
                        offset: 1,
                        color: '#f7b17a'
                    }])
                },
                markPoint : {
                    data : [
                        {type : 'max', name: '最大值'},
                        {type : 'min', name: '最小值'}
                    ]
                },
                markLine : {
                    data : [
                        {type : 'average', name : '平均值'}
                    ]
                }
            })
            legend.push('保费')
        }

        if (jsonData.ispolicy && jsonData.ispremium) {
            yAxis.push({
                type: 'value',
                name: '单量（' + unit + '单）',
                position: 'left'
            })
            yAxis.push({
                type: 'value',
                name: '保费（' + unit + '元）',
                position: 'right'
            })
            series[1].yAxisIndex = 1
        } else {
            yAxis.push({
                type : 'value'
            })
        }
        $('.partner_month_tr').show()

        // 设置标题
        // $('#partner_month_title').html(obj.CHANNEL_NAME + '合作伙伴各机构趋势图-总图')

        // 基于准备好的dom，初始化echarts实例
        var partnerMonth = echarts.init(document.getElementById('partner_month'),'cic');

        var option = {
            title : {
                text: obj.CHANNEL_NAME + '合作伙伴趋势图-总图',
                left: 'center'
            },
            grid: {
                top: 100
                // bottom: 80
            },
            tooltip : {
                trigger: 'axis'
            },
            legend: {
                data: legend,
                top: 30,
                left:30
            },
            toolbox: {
                show : true,
                top: 30,
                feature : {
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    data : months,
                    axisLabel: {
                        rotate: 45
                    }
                }
            ],
            yAxis: yAxis,
            dataZoom: [
                 {
                     type: 'inside'
                 }
             ],
            series : series
        };
        // 使用刚指定的配置项和数据显示图表。
        partnerMonth.setOption(option);

    }
    /* --------------------保费趋势图 end------------------------------- */
    /* --------------------保费趋势图 start------------------------------- */

    // 各机构占比变化情况
    function setDeptComparedCharts(data, jsonData) {
        if (!jsonData.ispolicy && !jsonData.ispremium) {
            return false
        }

        var type = $('#type_select').val()

        $('.dept_compared_tr').show()
        // 基于准备好的dom，初始化echarts实例
        var deptComparedChart = echarts.init(document.getElementById('dept_compared'),'cic');

        // 设置标题
        // $('#dept_compared_title').html(jsonData.CHANNEL_NAME + '机构趋势图')

        var legend = []
        var selected = {}
        var source = []
        var series = []
        var months = last_year_month()

        var product = []
        product.push('product')
        source.push(product.concat(months))
        // y坐标轴添加说明 单位 20191114 lfd added
        // var yAxis = {gridIndex: 0}
        var yAxis = {}

        if (type === '0') {
            // y坐标轴添加说明 单位 20191114 lfd added
            yAxis = {
                type: 'value',
                name: '保额（' + unit + '元）',
            }
        } else if (type === '1') {
            // y坐标轴添加说明 单位 20191114 lfd added
            yAxis = {
                type: 'value',
                name: '单量（' + unit + '单）',
            }
        }

        $.each(data, function (i, v) {
            var deptAbr = v.DEPT_ABR
            legend.push(deptAbr)
            if (i < 5) {
                selected[deptAbr] = true
            } else {
                selected[deptAbr] = false
            }

            var item = []
            item.push(deptAbr)

            if (type === '0') {
                for(var j = 11; j>=0; j--) {
                    item.push(v['PREMIUM'+j])
                }

            } else if (type === '1') {
                for(var j = 11; j>=0; j--) {
                    item.push(v['COUNT'+j])
                }

            } else {
                $.message("error", "查询错误，请重试！");
            }

            source.push(item)
            series.push({
                type: 'line', smooth: true, seriesLayoutBy: 'row', sssssareaStyle: {}
            })
        })




        var option = {
            title : {
                text: jsonData.CHANNEL_NAME + '机构趋势图',
                left: 'center'
            },
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross'
                }
            },
            legend: {
                data: legend,
                orient: 'vertical',
                type: 'scroll',
                right: 10,
                top: 20,
                bottom: 20,
                selected: selected
            },
            xAxis: {type: 'category'},
            yAxis: yAxis,
            series: series,
            dataset: {
                source: source
            }
        }

        deptComparedChart.setOption(option);
    }
    // 按区域按时间对比图
    function setDeptQuantityCharts(data, jsonData) {
        if (!jsonData.ispolicy && !jsonData.ispremium) {
            return false
        }

        $('.dept_quantity_tr').show()
        // 基于准备好的dom，初始化echarts实例
        var deptQuantityChart = echarts.init(document.getElementById('dept_quantity'),'cic');
        // 设置标题
        // $('#dept_quantity_title').html(jsonData.CHANNEL_NAME +  '机构对比图')

        var currentTime = $('#currentTime').val()
        var d = currentTime?new Date(currentTime.replace(/-/g, '/')) :new Date();
        var months = [];
        for(var i = 0; i < 12; i++) {
            var m = d.getMonth() + 1;
            m = m < 10 ? "0" + m : m;
            //在这里可以自定义输出的日期格式
            months.push(d.getFullYear() + "-" + m );
            d.setMonth(d.getMonth() - 1);
        }

        // 整理数据
        var obj = {}
        var deptAbrs = []
        $.each(data, function(item, value) {
            if (jsonData.ispolicy && jsonData.ispremium) {
                $.each(months, function (i, v) {
                    if (!obj[v]) {
                        obj[v] = []
                    }

                    deptAbrs.push(value.DEPT_ABR)

                    obj[v].push({
                        polNum: value['COUNT' + i],
                        premium: value['PREMIUM' + i],
                        dept_abr: value.DEPT_ABR
                    })
                })
            } else if (jsonData.ispolicy) {
                $.each(months, function (i, v) {
                    if (!obj[v]) {
                        obj[v] = []
                    }

                    deptAbrs.push(value.DEPT_ABR)

                    obj[v].push({
                        polNum: value['COUNT' + i],
                        dept_abr: value.DEPT_ABR
                    })
                })
            } else if (jsonData.ispremium) {
                $.each(months, function (i, v) {
                    if (!obj[v]) {
                        obj[v] = []
                    }

                    deptAbrs.push(value.DEPT_ABR)

                    obj[v].push({
                        premium: value['PREMIUM' + i],
                        dept_abr: value.DEPT_ABR
                    })
                })
            }
        })

        var options = []
        for (prop in obj) {
            var option = {}
            var item1 = []
            var item2 = []
            var item3 = []
            var item4 = []
            var xAxis = []
            var otherPolNum = 0
            var otherPremium = 0

            // 排序
            if (jsonData.ispolicy) {
                obj[prop].sort(function (a, b) {
                    return b.polNum - a.polNum
                })
            } else if (jsonData.ispremium){
                obj[prop].sort(function (a, b) {
                    return b.premium - a.premium
                })
            }
            $.each(obj[prop], function (i, v) {
                xAxis.push(v.dept_abr)
                if (jsonData.ispolicy) {
                    item1.push(v.polNum)
                }
                if (jsonData.ispremium){
                    item2.push(v.premium)
                }
                if (i < 5) {
                    if (jsonData.ispolicy) {
                        item3.push({
                            name: v.dept_abr,
                            value: v.polNum,
                            label: {
                                show: true
                            },
                            labelLine: {
                                show: true
                            }
                        })
                    }
                    if (jsonData.ispremium){
                        item4.push({
                            name: v.dept_abr,
                            value: v.premium,
                            label: {
                                show: true
                            },
                            labelLine: {
                                show: true
                            }
                        })
                    }
                } else {
                    if (jsonData.ispolicy) {
                        otherPolNum += (v.polNum- 0)
                    }
                    if (jsonData.ispremium){
                        otherPremium += (v.premium- 0)
                    }
                }

            })
            if (jsonData.ispolicy) {
                item3.push({
                     name: '其他',
                     value: otherPolNum,
                     label: {
                         show: true
                     },
                     labelLine: {
                         show: true
                     }
                 })
             }
             if (jsonData.ispremium){
                 item4.push({
                     name: '其他',
                     value: otherPremium,
                     label: {
                         show: true
                     },
                     labelLine: {
                         show: true
                     }
                 })
            }
            if (jsonData.ispolicy && jsonData.ispremium) {
                var series = [{
                    data: item1
                }, {
                    data: item2,
                    yAxisIndex: 1
                },{

                    data: item3
                },{
                    data: item4
                }]
            } else if  (jsonData.ispolicy){
                var series = [{
                    data: item1
                },{
                    data: item3
                }]
            } else if  (jsonData.ispremium){
                var series = [{
                    data: item2
                },{
                    data: item4
                }]
            }
            var legend = []
            if  (jsonData.ispolicy) {
                legend.push('单量')
            }
            if  (jsonData.ispremium){
                legend.push('保费')
            }
            option = {
                title : {
                    text: jsonData.CHANNEL_NAME +  '机构对比图',
                    left: 'center'
                },
                xAxis: {
                    data: xAxis
                },
                series: series,
                legend:{
                    data: legend
                }
            }
            options.push(option)
        }

        months.reverse()
        options.reverse()

        // yAxis
        var yAxis = []
        if (jsonData.ispolicy && jsonData.ispremium) {
             yAxis.push({
                 type: 'value',
                 name: '单量（' + unit + '单）',
                 position: 'left'
             })
             yAxis.push({
                 type: 'value',
                 name: '保费（' + unit + '元）',
                 position: 'right'
             })
         } else {
             yAxis.push({
                 type : 'value'
             })
         }
        var optionSeries

        if (jsonData.ispolicy && jsonData.ispremium) {

            optionSeries=[{
                name: '单量',
                type: 'bar'
            },{
                name: '保费',
                type: 'bar'
            },{
                name: '各机构保单占比',
                type: 'pie',
                radius: ['0', '35%'],
                center: ['25%', '25%'],
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                label: {
                  formatter: function(params) {
                    if(params.data.value == 0){
                        params.data.label.show = false;
                        params.data.labelLine.show = false;
                    }
                  }
                  // position: 'inside'
                }
            }, {
                name: '各机构保费占比',
                type: 'pie',
                radius: ['0', '35%'],
                center: ['75%', '25%'],
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                label: {
                    formatter: function(params) {
                        if(params.data.value == 0){
                            params.data.label.show = false;
                            params.data.labelLine.show = false;
                        }
                    }
                    // position: 'inside'
                }
            }]
        } else if (jsonData.ispolicy) {
            optionSeries = [{
                name: '单量',
                type: 'bar'
            },{
                name: '各机构保单占比',
                type: 'pie',
                radius: ['0', '35%'],
                center: ['50%', '25%'],
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                label: {
                  formatter: function(params) {
                      if(params.data.value == 0){
                          params.data.label.show = false;
                          params.data.labelLine.show = false;
                      }
                  }
                  // position: 'inside'
                }
            }]
        }else if (jsonData.ispremium) {
            optionSeries=[{
                name: '保费',
                type: 'bar'
            },{
                name: '各机构保费占比',
                type: 'pie',
                radius: ['0', '35%'],
                center: ['50%', '25%'],
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                label: {
                    formatter: function(params) {
                        if(params.data.value == 0){
                            params.data.label.show = false;
                            params.data.labelLine.show = false;
                        }
                        /* if(params.name !== '') {
                            return params.name + '\n' + '（' + params.value + '|' + params.percent + '%）';
                        }else {
                            return '';
                        } */
                    }
                    // position: 'inside'
                }
            }]
        }
        option = {
            baseOption: {
                timeline: {
                    axisType: 'category',
                    autoPlay: false,
                    playInterval: 2000,
                    currentIndex: (months.length - 1),
                    data: months
                },
                toolbox: {
                    show : true,
                    feature : {
                        restore : {show: true},
                        saveAsImage : {show: true},
                        dataView : {show: true, readOnly: false}
                    }
                },
                legend: {
                    x: 'right',
                    y: 'bottom'
                },
                tooltip: {

                },
                grid: {
                    top: '55%',
                    bottom: 100,
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'shadow',
                            label: {
                                show: true
                            }
                        }
                    }
                },
                xAxis: {
                    type:'category',
                    axisLabel: {
                        rotate: 45
                    }
                },
                yAxis: yAxis,
                series: optionSeries
            },
            options: options
        }

        deptQuantityChart.setOption(option);

    }
    /* --------------------各机构趋势图 end------------------------------- */
    /* ------------------------查询成本费用 start------------------------- */
    /* function getChannelCost(channelCode) {
        var jsonData = {
            channelCode: channelCode
        }

        $.ajax({
            url : "dataManage/queryChannelCost",
            type : 'POST',
            async : true,
            dataType:'json',
            data: jsonData,
            success : function(data) {
                // 成本展示
                if (data.length > 0) {
                    $('#channelCost').html(data[0].CHANNEL_COST)
                } else {
                    $('#channelCost').html('--')
                }
            }
        })
    } */
    /* ------------------------查询成本费用 end------------------------- */
    // 弹窗重置按钮 lfd added 20190909
    function tempReset() {
        $('#partner_name').val('')
        $('#partner_code').val('')
    }
    // 弹窗查询合作伙伴名称 lfd added 20190909
    function setPartnerParam(displayPage) {
        var jsonData = {
            current: displayPage,
            size: 5,
            partnerName: $('#partner_name').val(),
            partnerCode: $('#partner_code').val()
        }
        queryPartnerInfo(jsonData)
    }
    function queryPartnerInfo(jsonData) {
        if (!jsonData) {
            jsonData = {
                current: 1,
                size: 5
            }
        }
        $.openLoading();
        $.ajax({
            url : "dataManage/queryPartnerInfo",
            type : 'POST',
            async : true,
            dataType:'json',
            data: jsonData,
            success : function(page) {
                $.closeLoading();

                var radioObj ="<input class='input_fxk' name='radioPartner' type='radio'/>";
                var fieldNames = "CHANNEL_NAME,PARTNER_CODE";
                var tableContent = creatTable1(fieldNames,page,radioObj);
                var tableObj = $("#templetTable");
                tableObj.find("tbody").remove();
                tableObj.append(tableContent);

                var strPage = creatChannelPage(jsonData.current,6,page.maxPage,"95");
                var pageDIV = $("#templetpageDIV");
                pageDIV[0].innerHTML="";
                pageDIV.append(strPage);

                $("#searchPartnerDiv").OpenDiv();

                bindradio();

           }
       })
    }
    // 取消按钮 关闭弹窗并重置输入框 lfd 20190910
    function closePartnerDiv() {
        tempReset();
        closeCurrentDIV("searchPartnerDiv");
    }
    /* 选择高亮   lfd 20190910*/
    function bindradio(){
        $("input[name='radioPartner']").click(function(){
            $("input[name='radioPartner']").parent().parent().removeClass("table_highlighter");
            $(this).parent().parent().addClass("table_highlighter");
        });
    }
    // 点击确定 写入数据
    function setPartner() {
        $("#ptn_name").val($(".table_highlighter td").eq(1).html())
        $("#ptn_code").val($(".table_highlighter td").eq(2).html())
        closePartnerDiv()
    }
    //统一 关闭  窗口
    function closeCurrentDIV(obj){
        $("#"+obj).CloseDiv();
    }
    // 点击展开机构 todo
    function toggle_subbox() {
    	// 先清空
        if ($('.subtable_box').css('display') === 'block') {
        	close_subbox()
        }
        
        var partnerCode = getUrlParam('partnerCode')
        
        var jsonData = {
            "countDate": $('#currentTime').val()?$('#currentTime').val():(new Date()).Format('yyyy-MM-dd'),
            "partnerCode": partnerCode?partnerCode:$('#ptn_code').val(),
            "ispolicy": document.getElementById('ispolicy').checked,
            "ispremium": document.getElementById('ispremium').checked,
            "policyType": $('#product_line').val()=="99"?"2":($('#product_line').val()||''),
            "isLiability": $('#product_line').val()=="99"?true:false,
            "CHANNEL_NAME": $('#policyAmountTable tbody tr td').eq(1).text()
        }

        queryPartner(jsonData)
        $('.subtable_box').show()
    }
    // 清空机构数据
    function close_subbox() {
    	$('.subtable_box').hide()
        // 清除表格
        $('#subtable').find('tbody').empty();
    }
    </script>
</body>
